package myblog.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import myblog.dao.FavoriteDao;
import myblog.entity.FavoriteEntity;
import myblog.service.FavoriteService;
import myblog.vo.FavoriteVo;

public class FavoriteServiceImpl implements FavoriteService {
	private FavoriteDao dao= null;
	@Override
	public List<FavoriteVo> list() {
		List<FavoriteVo> voList = new ArrayList<FavoriteVo>();

		List<FavoriteEntity> entityList = dao.list();

		for (FavoriteEntity entity : entityList) {

			FavoriteVo vo = new FavoriteVo();

			// 对象属性值拷贝 entity => vo
			BeanUtils.copyProperties(entity, vo);

			voList.add(vo);
		}

		return voList;
	}

	@Override
	public void addFavorite(FavoriteVo favoriteVo) {
		dao.addFavorite(favoriteVo);
		
	}

	@Override
	public void delFavorite(String favorite_id) {
		dao.delFavorite(favorite_id);
		
	}
	
	public void setDao(FavoriteDao dao){
		this.dao = dao;
	}

}
